package com.cj.ctyl.controller.user;

import com.cj.ctyl.entity.SysUsers;
import com.cj.ctyl.framework.core.controller.BaseController;
import com.cj.ctyl.framework.core.page.TableDataInfo;
import com.cj.ctyl.framework.core.page.TableSupport;
import com.cj.ctyl.mapper.SysRolesMapper;
import com.cj.ctyl.service.SysRolesService;
import com.cj.ctyl.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: Alex
 * @Description: 用户Controller
 * @Date: 2021/8/22
 */
@Controller
@RequestMapping("/sysuser")
public class SysUsersController extends BaseController {

    private final String prefix = "/user";

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysRolesService sysRolesService;

    /**
     * 用户详情信息
     *
     * @param id 用户主键
     */
    @RequestMapping("/info")
    public String info(Long id, ModelMap mmap) {
        SysUsers sysUsers = sysUserService.selectSysUserById(id);
        mmap.put("user", sysUsers);
        return prefix + "/info";
    }


    @RequestMapping("/view")
    public String view(ModelMap mmap) {
        mmap.put("rolesList", sysRolesService.selectSysRolesList());
        return prefix + "/user";
    }


    @ResponseBody
    @RequestMapping("/list")
    public TableDataInfo list(SysUsers sysUsers) {
        startPage();
        List<SysUsers> sysUsers1 = sysUserService.selectSysUserList(sysUsers);
        return getDataTable(sysUsers1);
    }


}
